#include<iostream>
#include<vector>
#include<queue>
using namespace std;
const int N = 2e3 + 5, INF = 0x7fffffff;

int n, m;
vector<bool> view;
vector<int> dist, cnt;
vector<pair<int, int> >ph[N];

void spfa() {
    view.assign(n+1, false);
    dist.assign(n+1, INF);
    cnt.assign(n+1, 0);
    queue<int> q;
    dist[1] = 0;
    view[1] = true;
    q.push(1);

    while(!q.empty()) {
        int u = q.front(); q.pop();
        view[u] = false;
        for(auto &e : ph[u]) {
            int v = e.first, w = e.second;
            if(dist[v] > dist[u] + w) {
                dist[v] = dist[u] + w;
                cnt[v] = cnt[u] + 1;
                if(cnt[v] > n) {
                    cout << "YES\n";
                    return;
                }
                if(!view[v]) { view[v] = true; q.push(v); }
            }
        }
    }
    cout << (dist[1] < 0 ? "YES\n" : "NO\n");
}

int main() {
    int T;  cin >> T;
    while(T--) {
        cin >> n >> m;
        for(int i = 1; i <= n; ++i) ph[i].clear();
        for(int i = 0; i < m; ++i) {
            int u, v, w;  cin >> u >> v >> w;
            ph[u].push_back({v, w});
            if(w >= 0) ph[v].push_back({u, w});
        }
        spfa();
    }
    return 0;
}